package com.soft.mapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Banji;
import com.soft.entity.Dept;

import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
public class BanjiMapperTest {
	@Autowired
	private BanjiMapper banjiMapper;
	//@Test
	public void testSelect()
	{
		List<Banji> banjiList = banjiMapper.selectList(null);
		for(int i = 0;i < banjiList.size();i++)
		{
			System.out.println(banjiList.get(i).getBanjiRenshu());
		}
	}
	//@Test
	public void testinsert() {
	    Banji banji = new Banji();
	    banji.setBanjiRenshu("20");
	    banji.setBanjiTeacher("赵六");
	    banjiMapper.insert(banji);
	}
	//@Test
	public void updateTest() {
		Banji banji = new Banji();
		banji.setBanjiBanjihao("1");
	    banji.setBanjiRenshu("18");
	    banji.setBanjiTeacher("张三");
	    banjiMapper.updateById(banji);
	}
	//@Test
	public void updateQueryTest()
	{
		UpdateWrapper<Banji> uw = new UpdateWrapper<>();
		uw.gt("banji_banjihao", 4);
		Banji banji = new Banji();
		banji.setBanjiTeacher("李四");
		banjiMapper.update(banji,uw);
		int num = banjiMapper.update(banji,uw);
		System.out.println(num);
	}
	//@Test
		public void selectIdTest()
		{
			Banji banji = banjiMapper.selectById(2);
			System.out.println(banji.getBanjiRenshu());
		}
		@Test
		public void selectOneTest() {
			QueryWrapper<Banji> qw = new QueryWrapper<>();
			qw.gt("banji_banjihao", 4);
			try
			{
				Banji banji = banjiMapper.selectOne(qw);
				System.out.println(banji);
			}catch(Exception e)
			{
				System.out.println("用户名和密码重复，请修改密码");
			}

		}
	//@Test
	public void deleteTest() {
	    Banji banji = new Banji();
	    banji.setBanjiBanjihao("1");
	    banjiMapper.deleteById(banji);
	}
	//@Test
	public void deleteQueryTest()
	{
		QueryWrapper<Banji> qw = new QueryWrapper();
		qw.eq("banji_teacher", "赵六");
		banjiMapper.delete(qw);
	}
}
